package com.ruoyi.wvp.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;

import java.util.HashMap;

public class ApiAjaxResult extends HashMap<String, Object> {

    public static final String ERROR_TYPE = "errorType";

    public static final String CODE_TAG = "code";

    /**
     * 返回内容
     */
    public static final String MSG_TAG = "msg";

    /**
     * 数据对象
     */
    public static final String DATA_TAG = "data";

    public ApiAjaxResult(int code, String msg, String errorType,Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(ERROR_TYPE, errorType);
        if (StringUtils.isNotNull(data)) {
            super.put(DATA_TAG, data);
        }
    }

    public static ApiAjaxResult error(String msg,Object data) {
        return new ApiAjaxResult(0, msg, "ERROR", data);
    }
    public static ApiAjaxResult error(Object data) {
        return ApiAjaxResult.error("ERROR", data);
    }
    public static ApiAjaxResult success(String msg,Object data) {
        return new ApiAjaxResult(0, msg, "ERROR", data);
    }
    public static ApiAjaxResult success(Object data) {
        return ApiAjaxResult.success("SUCCESS",data);
    }
}
